<script>
export default {
  data() {
    return {
      item: {
        question: "hello",
        A: "",
        B: "",
        C: "",
        D: '',
        answer: '',
        type: 0
      },
      message: "hello wowrld"
    }
  },
  async created() {
    var myitem = ""
    try {
      const response = await this.$axios.get(this.$s_host + "/items/" + this.$route.params.id + "/" + this.$route.params.type
          + "/q_item")
      this.item = response.data;
    } catch (err) {
      console.error(err); // 打印错误
    }
  },
  methods: {
    change() {
      this.$axios.put("/items/q_put", this.item).then(function (response) {
        window.location.replace("/");
      }).catch(function (err) {
        alert(err)
      })
    },
    del() {
      this.$axios.delete("/items/" + this.item.id + "/" + this.item.type + "/q_del")
          .then(response => {
            // 处理成功响应
            console.log('Resource deleted successfully', response);
            window.location.replace("/");
          })
          .catch(error => {
            // 处理错误
            alert(error)
          });
    }
  }
}
</script>

<template>
  <div v-if='item.type==0'>
    <div style="margin: 20px 0">
      <el-input
          v-model="item.question"
          style="width: 500px"
          autosize
          type="textarea"
          placeholder="Please input"
      />
    </div>
    <div  style="margin: 20px 0">
      <el-input
          v-model="item.A"
          style="width: 500px"
          autosize
          type="textarea"
          placeholder="Please input"
      />
    </div>
    <div style="margin: 20px 0">
         <el-input
          v-model="item.B"
          style="width: 500px"
          autosize
          type="textarea"
          placeholder="Please input"
      />
    </div>
    <div style="margin: 20px 0">
      <el-input
          v-model="item.C"
          style="width: 500px"
          autosize
          type="textarea"
          placeholder="Please input"
      />
    </div>
    <div style="margin: 20px 0">
      <el-input
          v-model="item.D"
          style="width: 500px"
          autosize
          type="textarea"
          placeholder="Please input"
      />
    </div>
    <div style="margin: 20px 0">
      <el-input
          v-model="item.answer"
          style="width: 500px"
          autosize
          type="textarea"
          placeholder="Please input"
      />
    </div>
  </div>
  <div v-else>
    <div style="margin: 20px 0">
      <el-input
          v-model="item.question"
          style="width: 500px"
          autosize
          type="textarea"
          placeholder="Please input"
      />
    </div>
    <div style="margin: 20px 0">
      <el-input
          v-model="item.answer"
          style="width: 500px"
          autosize
          type="textarea"
          placeholder="Please input"
      />

    </div>
  </div>
  <el-button @click="change" type="success" round>更新</el-button>
  <el-button @click="del()" type="warning" round>删除</el-button>
</template>

<style scoped>

</style>